package com.ywk.spring.business.mapper.Impl;

import com.ywk.spring.business.entity.User;
import com.ywk.spring.business.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author zbh
 * @Date 2023/6/30
 */
@Component
public class UserMapperImpl implements UserMapper {

    //声明jdbc模板对象（jdbcTemplate），调用方法
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<User> findAll() {
        //准备sql语句
        String sql ="select id,name from tb_user";
        //调用方法，query：查询
        // update: 修改
        // BeanPropertyRowMapper：是jdbcTemplate内封装好的对象，保存着由查询所有方法及实体类属性得到的查询数据
        List<User> users = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(User.class));
        return users;
    }
}
